/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package backupit.core.report;

/**
 *
 * @author dbotelho
 */
public class ReportManager {
    private ReportQueue reportQueue;
    
    public ReportManager(){
        this.reportQueue = new ReportQueue();
    }
    /**
     * Executes all reports
     * @return number of reports exectuted
     */
    public int flush() throws InterruptedException{
        int count = 0;
        while(this.getReportQueue().size()!=0){
            Report report = this.getReportQueue().getFirst();
            if(this.flush(report)){
                this.getReportQueue().remove(report);
                count ++;
            }
        }
        return count;
    }
    
    
    public boolean flush(Report report) throws InterruptedException {
        this.getReportQueue().add(report);
        Thread t = new Thread(report);
        t.start();
        t.join();
        return this.getReportQueue().remove(report);
    }

    public ReportQueue getReportQueue() {
        return reportQueue;
    }

    public void setReportQueue(ReportQueue reportQueue) {
        this.reportQueue = reportQueue;
    }

}
